﻿@model IEnumerable<JustMVCTest.Models.PO>
@using JustMVCTest.Models
@{
    ViewBag.Title = "AllPOslist";
}
<html>
<head>
    <title></title>
</head>

<body>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>



            <script type="text/javascript">
                function gup(name) {
                    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
                    var regexS = "[\\?&]" + name + "=([^&#]*)";
                    var regex = new RegExp(regexS);
                    var results = regex.exec(window.location.href);
                    if (results == null)
                        return "";
                    else
                        return results[1];
                }
            </script>

            <script type="text/javascript">
                function valuefunction(x) {
                    document.pickform.Item.value = x;
                }

            </script>



            <script type="text/javascript">
                $(function () {
                    $("#Fromdatepicker").datepicker({ dateFormat: 'dd/mm/yy' });
                    $("#Todatepicker").datepicker({ dateFormat: 'dd/mm/yy' });
                });
	            </script>


<script type="text/javascript">
    function checkform() {
        if (pickform.Item.value == "NOTHING") {
            alert('INPUT ERROR');
            return false;
        }

        return true;
    }
    </script>

       
        @Html.ValidationSummary()
                 <form name="pickform1" method="link" style="margin:0px" action="@Url.Action("Index", "AllPOsList")" > 

       <table style="font-size: 1em;font-family:""Trebuchet MS"", Verdana, Helvetica, Sans-Serif;">
       <tr>
       <td>
               <fieldset style="height:200px;">
                <legend>Filter</legend>

               
               
                <table style="font-size: 1em;font-family:""Trebuchet MS"", Verdana, Helvetica, Sans-Serif;"> 
                <tr>
                <td style="border-color:transparent">
                  PO Number: 
                </td> 
                <td style="border-color:transparent"> 
                    @Html.TextBox("searchPONum")  @Html.ValidationMessage("searchPONum", "*") 
                </td>
                </tr>
                <tr>
                    <td style="border-color:transparent">  Item Number: </td> <td style="border-color:transparent">@Html.TextBox("searchItemNum","")  @Html.ValidationMessage("searchItemNum", "*") </td>
                </tr>
               <tr>
                  <td style="border-color:transparent">    Delivery Date: From:</td> <td style="border-color:transparent"> @(Html.Telerik().DatePicker() .Name("Fromdatepicker") )  @Html.ValidationMessage("Fromdatepicker", "*") &nbsp&nbsp To:  @(Html.Telerik().DatePicker() .Name("Todatepicker") )  @Html.ValidationMessage("Todatepicker", "*")  &nbsp&nbsp &nbsp&nbsp </td> </tr>
     
                  <tr> <td style="border-color:transparent">
                     Status: </td> <td style="border-color:transparent"> 
                     <select name="SearchStatus" id="SearchStatus" > 
                      <option value="3" selected="selected">All</option>
                      <option value="0">Open</option>
                      <option value="99">Closed</option>
                      <option value="1">Pending Close</option>
                      <option value="2">Pending Delivery Date</option>
                    </select> </td> </tr>
                    <tr>
                    <td style="border-color:transparent">
                    Vendor: </td>
                    <td style="border-color:transparent">
                        @Html.TextBox("searchVendor","") 
                    </td>
                    </tr>
                    </table>
            

                    </fieldset>       
       </td>
       
       <td>
                   <fieldset style="height:200px;">
            <legend>Fields To View</legend>

                    <table style="font-size: 1em;font-family:""Trebuchet MS"", Verdana, Helvetica, Sans-Serif;">
                    <tr>
                    <td valign="top">
                        <input type="checkbox" name="Description_Field" value="1"  />Description<br />
                        <input type="checkbox" name="Delivery_Date_Field" value="1"  />Delivery Date<br />
                        <input type="checkbox" name="Status_Field" value="1"  />Status<br />
                        <input type="checkbox" name="Requisitioner_Field" value="1"  />Requisitioner<br />
                        <input type="checkbox" name="DeliveryDate_Req_Field" value="1"  />DeliveryDate Reqeust<br />
                        <input type="checkbox" name="Cost_Cent_Field" value="1"  />Cost Center                    
                    </td>

                    <td valign="top">
                        <input type="checkbox" name= "Int_Order_Field" value="1"  />Int_Order<br />
                        <input type="checkbox" name= "Prof_Cent_Field" value="1"  />Prof_Cent<br />
                        <input type="checkbox" name= "Percentage_Field" value="1"  />Percentage<br />
                        <input type="checkbox" name= "cost_elem_Field" value="1"  />cost_elem<br />
                        <input type="checkbox" name= "co_el_name_Field" value="1"  />co_el_name<br />
                        <input type="checkbox" name= "Vendor_Field" value="1"  />Vendor                   
                    </td>

                    <td valign="top">
                        <input type  ="checkbox" name= "VendorName_Field" value="1" />Vendor Name<br />
                        <input type  ="checkbox" name= "UM_Field" value="1"  />UM<br />
                        <input type  ="checkbox" name= "T_Curr_Field" value="1"  />T_Curr<br />
                        <input type  ="checkbox" name= "Sch_Lin_Field" value="1"  />Sch_Lin<br />
                        <input type  ="checkbox" name= "Ord_Qty_Field" value="1"  />Ord_Qty<br />
                        <input type  ="checkbox" name= "Open_Qty_Field" value="1"  />Open_Qty
                    </td>

                    <td valign="top">
                        <input type  ="checkbox" name= "Order_Amt_Field" value="1"  />Order_Amt<br />
                        <input type  ="checkbox" name= "Open_Amt_L_Field" value="1" />Open_Amt_L<br />
                        <input type  ="checkbox" name= "TSSC_Pending_Send_Date_Field" value="1"  />TSSC_Send_Date<br />
                        <input type  ="checkbox" name= "Purchase_O_Field" value="1"  />Purchase_O                    
                    </td>

                    </tr>
                    </table>
                    
        </fieldset>
       </td>
       
       <td valign="middle">
            <input style="font-size:small" type="submit" value="Filter" name="Event" /> 
       </td>
       
       </tr>
       </table>

       </form>
       






</body>
      </html>


        @(Html.Telerik().Grid<PO>(Model)
        .Name("POesGrid")
        .DataKeys(keys =>
        {
            keys.Add(p => p.PONumber);
            keys.Add(p => p.Item);
            keys.Add(p => p.Update_Num);
        })
                .ToolBar(commands => commands
                            .Custom()
                            .HtmlAttributes(new { id = "exportTableToCSV" })
                            .Text("Export table to CSV")
                            .Action("AllPOsExportTableToCsv", "AllPOsList", new
                            {
                                Event = Request.QueryString["Event"],
                                searchPONum = Request.QueryString["searchPONum"],
                                searchItemNum = Request.QueryString["searchItemNum"],
                                Fromdatepicker = Request.QueryString["Fromdatepicker"],
                                Todatepicker = Request.QueryString["Todatepicker"],
                                SearchStatus = Request.QueryString["SearchStatus"],
                                searchVendor = Request.QueryString["searchVendor"],
                                                                                                
                                Delivery_Date_Field = Request.QueryString["Delivery_Date_Field"],
                                Description_Field = Request.QueryString["Description_Field"],
                                VendorName_Field = Request.QueryString["VendorName_Field"],
                                Status_Field = Request.QueryString["Status_Field"],
                                Requisitioner_Field = Request.QueryString["Requisitioner_Field"],
                                DeliveryDate_Req_Field = Request.QueryString["DeliveryDate_Req_Field"],
                                Cost_Cent_Field = Request.QueryString["Cost_Cent_Field"],
                                Int_Order_Field = Request.QueryString["Int_Order_Field"],
                                Prof_Cent_Field = Request.QueryString["Prof_Cent_Field"],
                                Percentage_Field = Request.QueryString["Percentage_Field"],
                                cost_elem_Field = Request.QueryString["cost_elem_Field"],
                                co_el_name_Field = Request.QueryString["co_el_name_Field"],
                                Vendor_Field = Request.QueryString["Vendor_Field"],
                                UM_Field = Request.QueryString["UM_Field"],
                                T_Curr_Field = Request.QueryString["T_Curr_Field"],
                                Sch_Lin_Field = Request.QueryString["Sch_Lin_Field"],
                                Ord_Qty_Field = Request.QueryString["Ord_Qty_Field"],
                                Open_Qty_Field = Request.QueryString["Open_Qty_Field"],
                                Open_Amt_T_Field = Request.QueryString["Open_Amt_T_Field"],
                                Order_Amt_Field = Request.QueryString["Order_Amt_Field"],
                                Open_Amt_L_Field = Request.QueryString["Open_Amt_L_Field"],
                                TSSC_Pending_Send_Date_Field = Request.QueryString["TSSC_Pending_Send_Date_Field"],
                                Purchase_O_Field = Request.QueryString["Purchase_O_Field"],   
                                isfirstload = Request.QueryString["isfirstload"]
                            })
                                                )
        .Columns(columns =>
        { 
            columns.Template(@<form name="pickform" style="margin:0px;padding:0px" action="@Url.Action("Index", "History")"> 
            <input type="hidden" value="@item.Item" name= "Item"/> <input type="hidden" value="@item.PONumber" name= "PONumber"/>
             <input style="padding:0;vertical-align:middle;text-align:center;font-size:small;height:30px" type="submit" value="History" /> </form>).Title("Commands").Width(150);
            columns.Bound(o => o.PONumber).Width(150);
            columns.Bound(o => o.Item).Width(100);
            
             if ((bool)ViewData["Status_Field"] == true)
            {
                columns.Template(@<script type="text/javascript">
                                   var x = @item.Status
                                   if (x == '1') {
                                       document.write("Pending Close");
                                   }
                                   if (x == '2') {
                                       document.write("Pending Delivery Date");
                                   }
                                   if (x == '0') {
                                       document.write("Open");
                                   }
                                   if (x == '99') {
                                       document.write("Closed");
                                   }

                    </script>).Title("Status").Width(100);
            }

             if ((bool)ViewData["Description_Field"] == true)
             {
                 columns.Bound(o => o.Descr).Width(600);

             }
             if ((bool)ViewData["Delivery_Date_Field"] == true)
             {
                 columns.Bound(o => o.DeliveryDate).Width(200).Format("{0:d}");
             }


             if ((bool)ViewData["Requisitioner_Field"] == true)
             {
                 columns.Bound(o => o.Requisitioner).Width(170);
             }

             if ((bool)ViewData["DeliveryDate_Req_Field"] == true)
             {
                 columns.Template(@<script type="text/javascript">
                                   var x = @item.Status
                                   if (x == '1') {
                                       document.write("");
                                   }
                                   if (x == '2') {
                                       document.write("@item.DeliveryDate_Req.ToShortDateString()");
                                   }
                                   if (x == '0') {
                                       document.write("");
                                   }
                                   if (x == '99') {
                                       document.write("");
                                   }

                    </script>).Title("Delivery Date Request").Width(200);
             }
             if ((bool)ViewData["Cost_Cent_Field"] == true)
             {
                 columns.Bound(o => o.Cost_Cent).Width(150);
             }
             if ((bool)ViewData["Int_Order_Field"] == true)
             {
                 columns.Bound(o => o.Int_Order).Width(150);
             }
             if ((bool)ViewData["Prof_Cent_Field"] == true)
             {
                 columns.Bound(o => o.Prof_Cent).Width(150);
             }
             if ((bool)ViewData["Percentage_Field"] == true)
             {
                 columns.Bound(o => o.Percentage).Width(150);
             }
             if ((bool)ViewData["cost_elem_Field"] == true)
             {
                 columns.Bound(o => o.cost_elem).Width(150);
             }
             if ((bool)ViewData["co_el_name_Field"] == true)
             {
                 columns.Bound(o => o.co_el_name).Width(200);
             }
             if ((bool)ViewData["Vendor_Field"] == true)
             {
                 columns.Bound(o => o.Vendor).Width(100);
             }
             if ((bool)ViewData["VendorName_Field"] == true)
             {
                 columns.Bound(o => o.VendorName).Width(300);
             }
             if ((bool)ViewData["UM_Field"] == true)
             {
                 columns.Bound(o => o.UM).Width(100);
             }
             if ((bool)ViewData["T_Curr_Field"] == true)
             {
                 columns.Bound(o => o.T_Curr).Width(150);
             }
             if ((bool)ViewData["Sch_Lin_Field"] == true)
             {
                 columns.Bound(o => o.Sch_Lin).Width(100);
             }
             if ((bool)ViewData["Ord_Qty_Field"] == true)
             {
                 columns.Bound(o => o.Ord_Qty).Width(100);
             }
             if ((bool)ViewData["Open_Qty_Field"] == true)
             {
                 columns.Bound(o => o.Open_Qty).Width(100);
             }
             if ((bool)ViewData["Open_Amt_T_Field"] == true)
             {
                 columns.Bound(o => o.Open_Amt_T).Width(100);
             }
             if ((bool)ViewData["Order_Amt_Field"] == true)
             {
                 columns.Bound(o => o.Order_Amt).Width(100);
             }
             if ((bool)ViewData["Open_Amt_L_Field"] == true)
             {
                 columns.Bound(o => o.Open_Amt_L).Width(100);
             }
             if ((bool)ViewData["TSSC_Pending_Send_Date_Field"] == true)
             {
                 columns.Bound(o => o.TSSC_Pending_Send_Date).Width(100);
             }
             if ((bool)ViewData["Purchase_O_Field"] == true)
             {
                 columns.Bound(o => o.Purchase_O).Width(100);
             }

        })

                                               .CellAction(cell =>
                                               {
                                                   if (cell.Column.Member == "Status")
                                                   {
                                                       PO po = cell.DataItem;


                                                   }
                                               })

                                               .Pageable(paging => paging.PageSize(6))
                                               .Sortable()
                                               .Scrollable(c => c.Height("240px"))
                                               .Resizable(resizing => resizing.Columns(true))
                                           )

    <div align="center">
  <form name="pickform2" method="link" action="@Url.Action("Index", "AllPOsList")">
        <input type="hidden" name="searchPONum" value="" />
        <input type="hidden" name="searchItemNum" />
        <input type="hidden" name="searchVendor" />
        <input type="hidden" name="SearchStatus" />
        <input type="hidden" name="Fromdatepicker" />
        <input type="hidden" name="Todatepicker" />
        <input type="hidden" name= "Description_Field" value="1" />
        <input type="hidden" name= "VendorName_Field" value="1" />
        <input type="hidden" name= "Delivery_Date_Field" value="1" />
        <input type="hidden" name= "Status_Field" value="1" />
        <input type="hidden" name= "Requisitioner_Field" value="1"  /> 
        <input type="hidden"name= "DeliveryDate_Req_Field" value="1"  />
        <input type="hidden" name= "Cost_Cent_Field" value="1"  /> 
        <input type="hidden" name= "Int_Order_Field" value="1"  />
        <input type="hidden" name= "Prof_Cent_Field" value="1"  /> 
        <input type="hidden" name= "Percentage_Field" value="1"  /> 
        <input type="hidden" name= "cost_elem_Field" value="1"  /> 
        <input type="hidden" name= "co_el_name_Field" value="1"  /> 
        <input type="hidden" name= "Vendor_Field" value="1"  /> 
        <input type="hidden" name= "UM_Field" value="1"  /> 
        <input type="hidden" name= "T_Curr_Field" value="1"  /> 
        <input type="hidden" name= "Sch_Lin_Field" value="1"  />
        <input type="hidden" name= "Ord_Qty_Field" value="1"  /> 
        <input type="hidden"name= "Open_Qty_Field" value="1"  /> 
        <input type="hidden" name= "Open_Amt_T_Field" value="1"  /> 
        <input type="hidden"name= "Order_Amt_Field" value="1"  /> 
        <input type="hidden" name= "Open_Amt_L_Field" value="1"  /> 
        <input type="hidden"name= "TSSC_Pending_Send_Date_Field" value="1"  /> 
        <input type="hidden" name= "Purchase_O_Field" value="1"  />
    </form>
        
                       <script type="text/javascript">
                           var param = gup("Event");
                           var param1 = gup("searchPONum");
                           document.pickform1.searchPONum.value = '@ViewData["PONumValue"]';
                           document.pickform2.searchPONum.value = param1;
                           var param4 = gup("searchItemNum");
                           document.pickform1.searchItemNum.value = '@ViewData["ItemNumValue"]';
                           document.pickform2.searchItemNum.value = param4;
                           var param5 = gup("searchVendor");
                           document.pickform1.searchVendor.value = '@ViewData["VendorValue"]';
                           document.pickform2.searchVendor.value = param5;
                           var param6 = gup("SearchStatus");
                           if (param6 == "") {
                               param6 = "3";
                           }
                           document.pickform1.SearchStatus.value = '@ViewData["StatusValue"]';
                           document.pickform2.SearchStatus.value = param6;
                           var param2 = gup("Fromdatepicker");
                           document.pickform1.Fromdatepicker.value = '@ViewData["DeliveryDateFromValue"]';
                           document.pickform2.Fromdatepicker.value = param2.replace(/%2F/gi, "/");
                           var param3 = gup("Todatepicker");
                           document.pickform1.Todatepicker.value = '@ViewData["DeliveryDateToValue"]';
                           document.pickform2.Todatepicker.value = param3.replace(/%2F/gi, "/");

                           var param7 = gup("Description_Field");
                           if ('@ViewData["Description_Field"]' == "True") {
                               document.pickform1.Description_Field.checked = true;
                           }
                           else {
                               document.pickform1.Description_Field.checked = false;
                               document.pickform2.Description_Field.value = 0;
                           }

                           var param7 = gup("VendorName_Field");
                           if ('@ViewData["VendorName_Field"]' == "True") {
                               document.pickform1.VendorName_Field.checked = true;
                           }
                           else {
                               document.pickform2.VendorName_Field.value = 0;
                           }

                           var param7 = gup("Delivery_Date_Field");
                           if ('@ViewData["Delivery_Date_Field"]' == "True") {
                               document.pickform1.Delivery_Date_Field.checked = true;
                           }
                           else {
                               document.pickform2.Delivery_Date_Field.value = 0;
                           }
                           var param7 = gup("Status_Field");
                           if ('@ViewData["Status_Field"]' == "True") {
                               document.pickform1.Status_Field.checked = true;
                           }
                           else {
                               document.pickform2.Status_Field.value = 0;
                           }
                           var param7 = gup("Requisitioner_Field");
                           if ('@ViewData["Requisitioner_Field"]' == "True") {
                               document.pickform1.Requisitioner_Field.checked = true;
                           }
                           else {
                               document.pickform2.Requisitioner_Field.value = 0;
                           }
                           var param7 = gup("DeliveryDate_Req_Field");
                           if ('@ViewData["DeliveryDate_Req_Field"]' == "True") {
                               document.pickform1.DeliveryDate_Req_Field.checked = true;
                           }
                           else {
                               document.pickform2.DeliveryDate_Req_Field.value = 0;
                           }
                           var param7 = gup("Cost_Cent_Field");
                           if ('@ViewData["Cost_Cent_Field"]' == "True") {
                               document.pickform1.Cost_Cent_Field.checked = true;
                           }
                           else {
                               document.pickform2.Cost_Cent_Field.value = 0;
                           }
                           var param7 = gup("Int_Order_Field");
                           if ('@ViewData["Int_Order_Field"]' == "True") {
                               document.pickform1.Int_Order_Field.checked = true;
                           }
                           else {
                               document.pickform2.Int_Order_Field.value = 0;
                           }
                           var param7 = gup("Prof_Cent_Field");
                           if ('@ViewData["Prof_Cent_Field"]' == "True") {
                               document.pickform1.Prof_Cent_Field.checked = true;
                           }
                           else {
                               document.pickform2.Prof_Cent_Field.value = 0;
                           }
                           var param7 = gup("Percentage_Field");
                           if ('@ViewData["Percentage_Field"]' == "True") {
                               document.pickform1.Percentage_Field.checked = true;
                           }
                           else {
                               document.pickform2.Percentage_Field.value = 0;
                           }
                           var param7 = gup("cost_elem_Field");
                           if ('@ViewData["cost_elem_Field"]' == "True") {
                               document.pickform1.cost_elem_Field.checked = true;
                           }
                           else {
                               document.pickform2.cost_elem_Field.value = 0;
                           }
                           var param7 = gup("co_el_name_Field");
                           if ('@ViewData["co_el_name_Field"]' == "True") {
                               document.pickform1.co_el_name_Field.checked = true;
                           }
                           else {
                               document.pickform2.co_el_name_Field.value = 0;
                           }
                           var param7 = gup("Vendor_Field");
                           if ('@ViewData["Vendor_Field"]' == "True") {
                               document.pickform1.Vendor_Field.checked = true;
                           }
                           else {
                               document.pickform2.Vendor_Field.value = 0;
                           }
                           var param7 = gup("UM_Field");
                           if ('@ViewData["UM_Field"]' == "True") {
                               document.pickform1.UM_Field.checked = true;
                           }
                           else {
                               document.pickform2.UM_Field.value = 0;
                           }
                           var param7 = gup("T_Curr_Field");
                           if ('@ViewData["T_Curr_Field"]' == "True") {
                               document.pickform1.T_Curr_Field.checked = true;
                           }
                           else {
                               document.pickform2.T_Curr_Field.value = 0;
                           }

                           
                           </script>
                           <script language ="javascript" > 

                           var param7 = gup("Sch_Lin_Field");
                           if ('@ViewData["Sch_Lin_Field"]' == "True") {
                               document.pickform1.Sch_Lin_Field.checked = true;
                           }
                           else {
                               document.pickform2.Sch_Lin_Field.value = 0;
                           }
                           var param7 = gup("Ord_Qty_Field");
                           if ('@ViewData["Ord_Qty_Field"]' == "True") {
                               document.pickform1.Ord_Qty_Field.checked = true;
                           }
                           else {
                               document.pickform2.Ord_Qty_Field.value = 0;
                           }
                           var param7 = gup("Open_Qty_Field");
                           if ('@ViewData["Open_Qty_Field"]' == "True") {
                               document.pickform1.Open_Qty_Field.checked = true;
                           }
                           else {
                               document.pickform2.Open_Qty_Field.value = 0;
                           }

                           var param7 = gup("Open_Amt_T_Field");
                           if ('@ViewData["Open_Amt_T_Field"]' == "True") {
                               document.pickform1.Open_Amt_T_Field.checked = true;
                           }
                           else {
                               document.pickform2.Open_Amt_T_Field.value = 0;
                           }

                           var param7 = gup("Order_Amt_Field");

                           if ('@ViewData["Order_Amt_Field"]' == "True") {
                               document.pickform1.Order_Amt_Field.checked = true;
                           }
                           else {
                               document.pickform2.Order_Amt_Field.value = 0;
                           }
                           var param7 = gup("Open_Amt_L_Field");
                           if ('@ViewData["Open_Amt_L_Field"]' == "True") {
                               document.pickform1.Open_Amt_L_Field.checked = true;
                           }
                           else {
                               document.pickform2.Open_Amt_L_Field.value = 0;
                           }
                           var param7 = gup("TSSC_Pending_Send_Date_Field");

                           if ('@ViewData["TSSC_Pending_Send_Date_Field"]' == "True") {
                               document.pickform1.TSSC_Pending_Send_Date_Field.checked = true;
                           }
                           else {
                               document.pickform2.TSSC_Pending_Send_Date_Field.value = 0;
                           }
                           var param7 = gup("Purchase_O_Field");
                           if ('@ViewData["Purchase_O_Field"]' == "True") {
                               document.pickform1.Purchase_O_Field.checked = true;
                           }
                           else {
                               document.pickform2.Purchase_O_Field.value = 0;
                           }
            </script>  
        
</div>

